import axios from "axios";
import router from "../routes";
import Cookies from "js-cookie";
import { Message } from "element-ui";

var instance = axios.create({
  timeout: 50000,
});

//   if(process.env.NODE_ENV === 'development'){
//       //开发环境
//       instance.baseURL = process.env.API_ROOT
//   }else{
//       //生产环境
//       instance.baseURL = 'www.baidu.com'
//   }
//添加请求拦截
instance.interceptors.request.use(
  (config) => {
    config.headers["API-User-Token"] = sessionStorage.getItem("token");
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// 添加响应拦截器
instance.interceptors.response.use(
  (response) => {
    if (response.status == 200) {
      return response.data;
    } else {
      Message.warning(response.data.message);
    }
  },
  (error) => {
    Message.error(response.data.message);
    return Promise.reject(error);
  }
);

export default instance;
